package 第六周;

/*
 * @author  YxinMiracle
 * @date  2022-05-05 19:58
 * @Gitee: https://gitee.com/yxinmiracle
 */

public class 乘积最大子数组 {

    public int maxProduct(int[] nums) {
        int n = nums.length;
        int[] fmax = new int[n];
        int[] fmin = new int[n];
        fmax[0] = nums[0];
        fmin[0] = nums[0];
        int max = nums[0];
        for (int i = 1; i < n; i++) {
            fmax[i] = Math.max(nums[i],Math.max(fmax[i-1]*nums[i],fmin[i-1]*nums[i]));
            fmin[i] = Math.min(nums[i],Math.min(fmax[i-1]*nums[i],fmin[i-1]*nums[i]));
            max = Math.max(fmax[i],max);
        }
        return max;
    }


}
